package com.yunshipei.inter.JsInterface;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.yunshipei.common.Globals;
import com.yunshipei.manager.YspPreferences;
import com.yunshipei.model.YspEvent.HomeFragmentEvent;
import com.yunshipei.utils.FileUtils;

import io.rong.eventbus.EventBus;

public class HomeJsObject extends BaseHomeJsObject {
    private Activity activity;

    public HomeJsObject(Activity activity) {

        super();
        this.activity=activity;
        Log.e("ssss","fff");
    }

    @org.xwalk.core.JavascriptInterface
    public void loadEnterURL(final String url, final String type, final String title) {

        EventBus.getDefault().post(new HomeFragmentEvent(url, title, type));
    }
    @org.xwalk.core.JavascriptInterface
    public void setThirdPartyApp(String type) {

        Log.e("ddd",type);

       if (type.equals("youjian")){
           FileUtils.sendEmail(activity);
       } else {
           Uri uri = Uri.parse(type);
           Intent intent = new Intent(Intent.ACTION_VIEW, uri);
           activity.startActivity(intent);
       }
    }
    @org.xwalk.core.JavascriptInterface
    public String ADname() {
        Log.e("AD",
                "{\"adName\":\""+YspPreferences.getInstance().getSharedPreferences().getString(Globals.USER_NAME,"")+"\",\"adSessionID\":\""+YspPreferences.getInstance().getSharedPreferences().getString("SessionID","")+"\"}");
        return "{\"adName\":\""+YspPreferences.getInstance().getSharedPreferences().getString(Globals.USER_NAME,"")+"\",\"adSessionID\":\""+YspPreferences.getInstance().getSharedPreferences().getString("SessionID","")+"\"}";
    }

}
